package com.xuanyuan.material

import android.annotation.SuppressLint
import android.content.res.ColorStateList
import android.graphics.Color
import android.os.Bundle
import android.view.View
import android.widget.TextView
import android.widget.Toast
import com.google.android.material.snackbar.Snackbar
import com.xuanyuan.base.BaseActivity
import com.xuanyuan.material.databinding.ActivitySnackBarBinding


class SnackBarActivity : BaseActivity<ActivitySnackBarBinding>(), View.OnClickListener {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mBinding.click = this

        //带按钮的


    }

    override fun initLayout(): Int {
        return R.layout.activity_snack_bar
    }

    @SuppressLint("UseCompatLoadingForColorStateLists")
    override fun onClick(v: View?) {
        if (v == null) {
            return
        }
        if (v == mBinding.btnCommon) {
            Snackbar.make(mBinding.cdl, "Snackbar massage", Snackbar.LENGTH_LONG)
                .setAction("action") {
                    Toast.makeText(this@SnackBarActivity, "click Snackbar", Toast.LENGTH_SHORT)
                        .show()
                }.show()

        } else if (v == mBinding.btnSelfCustomer) {

            val snackbar = Snackbar.make(mBinding.cdl, "Customer Snackbar ", Snackbar.LENGTH_LONG)

            val csl: ColorStateList =
                resources.getColorStateList(R.color.colorlist_button_text_common)

            // 设置Message颜色
            snackbar.setTextColor(csl)
            // 设置Action 文字颜色
            snackbar.setActionTextColor(csl)

            //设置Snack ItemView的背景色
            snackbar.setBackgroundTint(resources.getColor(R.color.white_background))
            snackbar.setAction("action") {
                Toast.makeText(this@SnackBarActivity, "click Snackbar", Toast.LENGTH_SHORT)
                    .show()
            }.show()

        } else if (v == mBinding.btnDepthCustomer) {

            val snackbar =
                Snackbar.make(mBinding.cdl, "Depth Customer Snackbar ", Snackbar.LENGTH_LONG)

            // 设置Message TextView 颜色,等同设置Message颜色
            val view: TextView = snackbar.view.findViewById(R.id.snackbar_text) as TextView
            view.setTextColor(Color.RED)
            view.setBackgroundColor(Color.WHITE)

            view.textSize = 18.0f

            // 设置Action 文字颜色
            val actionView: TextView = snackbar.view.findViewById(R.id.snackbar_action) as TextView
            actionView.setTextColor(resources.getColor(R.color.white))

            //设置Snack ItemView的背景色,等同 snackbar.setBackgroundTint
            snackbar.view.rootView.setBackgroundColor(resources.getColor(R.color.color30))

            snackbar.setAction("action") {
                Toast.makeText(this@SnackBarActivity, "click Snackbar", Toast.LENGTH_SHORT)
                    .show()
            }.show()

        }

    }

    override fun afterInit() {

    }


}
